from django.forms.models import model_to_dict

# 话术分类模型转字典
def script_category_to_dict(category):
    """
    将ScriptCategory模型转换为字典格式，用于API响应
    """
    category_dict = model_to_dict(category, exclude=['deleted'])
    category_dict["category_id"] = str(category.category_id)
    # 格式化状态字段
    category_dict["status"] = {
        "code": category.status,
        "message": category.get_status_display(),
    }
    # 格式化时间字段
    category_dict["create_time"] = category.create_time.strftime("%Y-%m-%d %H:%M:%S")
    category_dict["update_time"] = category.update_time.strftime("%Y-%m-%d %H:%M:%S")
    return category_dict